﻿using System.Runtime.Serialization;
using System.Web.Mvc;

namespace Ndex.Core
{
    [DataContract]
    public class NameModel
    {
        public NameModel() 
        {
            Id = 0;
            Name = string.Empty;
        }

        [DataMember]
        public long Id { get; set; }

        [DataMember]
        public string Name { get; set; }

        public NameModel(IName data)
            : this()
        {
            if (data == null) return;
            Id = data.Id;
            Name = data.Name;
        }

        public override string ToString()
        {
            return string.Format("{0}.{1}", Id, Name);
        }

        public static implicit operator SelectListItem(NameModel i)
        {
            return new SelectListItem { Value = i.Id.ToString(), Text = i.Name};
        }
    }

    public interface IName
    {
        long Id { get; set; }
        string Name { get; set; }
    }
}
